<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title></title>
<script type="text/javascript" src="jquery-1.12.4.min.js"></script>
<script>
	var col_count = 1;
	function add(){
		col_count++;
		var html = '';
		html += '<div id="colTemp_' + col_count + '">';
		html += '	<input type="text" id="col_' + col_count + '">';
		html += '	<textarea id="val_' + col_count + '"></textarea>';
		html += '	<input type="button" onclick="del(this)" value="-">';
		html += '</div>';
		$("#col_val").append(html);
	}
	
	function createsql(){
	
		var allSql = '';
	
		var line = $("#line").val();
		
		var sqlTemplate = $("#sqlTemplate").val();
		
		var cols = $("input[id^='col_']");
		var vals = $("textarea[id^='val_']");
		
		var valsArr = new Array();
		for(var i=0;i<vals.length;i++){
			valsArr[i] = $(vals[i]).val().split(/[(\r\n)\r\n]+/);
		}
		
		for(var i=0;i<line;i++){
			var s = sqlTemplate + '';
			for(var j=0;j<cols.length;j++){
				s = s.replace($(cols[j]).val(), valsArr[j][i]);
			}
			s = s.replace('[?no?]', i);
			allSql += s + '\r';
		}
		
		
		$("#sql").val(allSql);
	}
	
	function del(obj){
		$(obj).parent().remove();
	}
</script>
</head>
<body>
<form>
	<span>sql总条数</span>
	<input type="text" id="line">
	<input type="button" value="生成sql" onclick="createsql()">
	<br>
	
	<span>sql脚本模板：替换的变量用[?xxx?]表示, [?no?]是特定参数，自增序号</span>
	<textarea id="sqlTemplate"></textarea>
	<br>
	
	<span>字段和值，其中值需要换行</span>
	<input type="button" value="增加字段" onclick="add()">
	<div id="col_val">
	
		<div id="colTemp_1">
			<input type="text" id="col_1">
			<textarea id="val_1"></textarea>
			<input type="button" onclick="del(this)" value="-">
		</div>
	
	</div>
	
	<span>脚本生成</span>
	<br>
	<textarea id="sql">
		
	</textarea>
</form>
</body>
</html> 